package priv.tuyou.myself;

import java.util.Arrays;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class StreamTest {

	public static void main(String[] args) throws Exception {
		
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		env.socketTextStream("192.168.142.129", 8888)
		.flatMap((String value, final Collector<Tuple2<String, Integer>> out) -> {  //必须写参数泛型，否则报错
			String[] words = value.split("\\W+");
			Arrays.stream(words).forEach(w -> {
				out.collect(new Tuple2<String, Integer>(w, 1));
			});
		}).keyBy(0).countWindow(5).sum(1).print();
		env.execute();
		
	}
}
